package org.corey.share.misc;

import java.util.Map;

import com.google.appengine.api.datastore.Text;
import com.opensymphony.xwork2.conversion.impl.DefaultTypeConverter;

public class GoogleTextConvertor extends DefaultTypeConverter {

	@Override
	public Object convertValue(Map<String, Object> context, Object value,
			Class toType) {
		if (toType.equals(Text.class)) {
			String[] inputArray = null;
			String input = "";
			if (value != null) {
				inputArray = (String[]) value;
			}
			if (inputArray != null && inputArray.length > 0) {
				input = inputArray[0];
			}
			Text text = new Text(input);
			return text;
		} else {
			Text text = (Text) value;
			return text.toString();
		}
	}

}
